#!/usr/bin/env python
#coding=utf-8

from codingabc.database import db
from app.models.MyModel import MyModelService

class Menu(db.Model, MyModelService):
    __bind_key__ = 'huiwang'
    __tablename__ = 'menu'

    menu_id = db.Column(db.Integer, primary_key=True)
    parent_id = db.Column(db.Integer, default=0)
    endpoint = db.Column(db.String(255), default='')
    endpoint_name = db.Column(db.String(255), default='')
    endpoint_icon = db.Column(db.String(255), default='')
    sort_order = db.Column(db.Integer, default=0)

    def __str__(self):
        return "Menu => { \
menu_id:%d, parent_id:%d, endpoint:'%s', endpoint_name:'%s', endpoint_icon:'%s',  \
sort_order:%d}" % (
self.menu_id, self.parent_id, self.endpoint, self.endpoint_name, self.endpoint_icon,
self.sort_order)

    __repr__ = __str__

    @staticmethod
    def get_child_list(id=0):
        """获取子菜单列表"""
        menu_child_list = Menu.query.filter(Menu.parent_id == id).\
                                    order_by(Menu.sort_order.desc()).all()

        return menu_child_list
